//
//  PersonPingjiaViewController.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/8/24.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "PersonPingjiaViewController.h"
#import "PingjiaTableViewCell.h"
#import "PersonDetailViewController.h"

@interface PersonPingjiaViewController ()<UITableViewDelegate,UITableViewDataSource,userJumeDelegate>
{
    UITableView * contentTableview;
    UIButton * button1;
    UIButton * button2;
    UIView * indititor;
    NSArray * dataArr;
}

@end

@implementation PersonPingjiaViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
    {
        
    }
    return self;
}

-(void)requestData
{
    if (button1.selected)
    {
        [NetRequestCenter evaluatewithtaskid:self.contentId type:@"0" d:@"1" page:@"1" result:^(BOOL success, NSDictionary *resultDic) {
            if (success) {
                dataArr = [[resultDic objectForKey:@"data"]objectForKey:@"Detail"];
                [contentTableview reloadData];
            }
        }];
    }
    else
    {
        [NetRequestCenter evaluatewithtaskid:self.contentId type:@"0" d:@"0" page:@"1" result:^(BOOL success, NSDictionary *resultDic) {
            if (success) {
                dataArr = [[resultDic objectForKey:@"data"]objectForKey:@"Detail"];
                [contentTableview reloadData];
            }
        }];
    }
}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    
    button1 = [[UIButton alloc]initWithFrame:CGRectMake(0, rectStatus.size.height + rectNav.size.height, ScreenWidth/2, 50)];
    [button1 setTitle:@"发出的评价" forState:UIControlStateNormal];
    button1.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [button1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [button1 setTitleColor:themeColor forState:UIControlStateSelected];
    [button1 addTarget:self action:@selector(button1Action) forControlEvents:UIControlEventTouchUpInside];
    button1.selected = YES;
    [self.view addSubview:button1];
    
    button2 = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2, rectStatus.size.height + rectNav.size.height, ScreenWidth/2, 50)];
    [button2 setTitle:@"收到的评价" forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [button2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [button2 setTitleColor:themeColor forState:UIControlStateSelected];
    [button2 addTarget:self action:@selector(button2Action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    indititor = [[UIView alloc]initWithFrame:CGRectMake(0, rectStatus.size.height + rectNav.size.height + 48, 80, 2)];
    indititor.backgroundColor = themeColor;
    [self.view addSubview:indititor];
    
    indititor.center = CGPointMake(ScreenWidth/4, indititor.center.y);
    
    contentTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, rectStatus.size.height + rectNav.size.height + 50, ScreenWidth, ScreenHeight - rectStatus.size.height - rectNav.size.height - 50) style:UITableViewStylePlain];
    contentTableview.delegate = self;
    contentTableview.dataSource = self;
    contentTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:contentTableview];
    
    [self requestData];
}

-(void)button1Action
{
    button1.selected = YES;
    button2.selected = NO;
    indititor.center = CGPointMake(ScreenWidth/4, indititor.center.y);
    [self requestData];
}

-(void)button2Action
{
    button2.selected = YES;
    button1.selected = NO;
    indititor.center = CGPointMake(ScreenWidth/4 * 3, indititor.center.y);
    [self requestData];
}

#pragma mark - tableView

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataArr count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [PingjiaTableViewCell height];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifer = @"pingjia";
    PingjiaTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
    if (!cell) {
        cell = [[PingjiaTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    cell.delegate = self;
    [cell loadData:[dataArr objectAtIndex:indexPath.row]];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(void)userId:(NSString *)userid
{
    PersonDetailViewController * person = [[PersonDetailViewController alloc]init];
    person.uid = userid;
    [self.navigationController pushViewController:person animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

